package mfgrep;

import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;

/**
 * Holds options set by user.
 * 
 * Class is NOT thread safe!
 * 
 * @author lzapletal
 */
class ProgramOptions {

  private boolean caseSensitive;
  private boolean recurse;
  HashSet<String> extensions = new HashSet<String>();

  public boolean isCaseSensitive() {
	return caseSensitive;
  }

  public void setCaseSensitive(boolean caseSensitive) {
	this.caseSensitive = caseSensitive;
  }

  public boolean isRecurse() {
	return recurse;
  }

  public void setRecurse(boolean recurse) {
	this.recurse = recurse;
  }

  public boolean hasExtension(String ext) {
	return extensions.contains(ext);
  }

  public void setExtensions(String exts) throws ProcessingException {
	StringTokenizer tizer = new StringTokenizer(exts, ",");
	try {
	  while (true) {
		String token = tizer.nextToken();
		// yes, limitation but I want to have it fast
		if (token.length() != 3)
			throw new ProcessingException("Extensions can be only 3 characters in length");
		extensions.add(token);
	  }
	} catch (NoSuchElementException e) {
		// done parsing
	}
  }
}
